package com.zhangtai.modules.dao;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhangtai.modules.dto.SecurityChangeDto;
import com.zhangtai.modules.entity.security.SecurityBatchEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2020-10-12 10:40:19
 */
@Mapper
public interface SecurityBatchDao extends BaseMapper<SecurityBatchEntity> {
    @Select("<script>Select c.*  from tb_security_batch c " +
            "left join tb_security s on s.security_id = c.security_id  " +
            "<where> c.is_delete = 0 " +
            "<if test='time!=null and time!=&apos;&apos;' >and c.operate_time &gt;= #{time} and c.operate_time &lt;=#{endTime} </if>" +
            "<if test='unitName!=null'> and  c.unit_name like '${unitName}'  </if>" +
            "<if test='orgName!=null'> and  c.org_name like '${orgName}'  </if>" +
            "<if test='name!=null'> and  c.name like '${name}'  </if>" +
            "<if test='type!=null'> and c.type =#{type}  </if>" +
            "<if test='contractIds!=null and contractIds.size>0'> and s.contract_main_id in " +
            " <foreach item=\"contractId\" index=\"index\" collection=\"contractIds\" open=\"(\" separator=\",\" close=\")\">#{contractId}</foreach>" +
            "</if>" +
            "<if test='contractIds==null or contractIds.size==0'> and s.contract_main_id = null </if>" +
            "</where> ORDER BY operate_time DESC" +
            "</script>")
    List<SecurityBatchEntity> getBatchListAuth(@Param(value = "contractIds") List<Long> contractIds,
                                               @Param(value = "unitName") String unitName,
                                               @Param(value = "orgName") String orgName,
                                               @Param(value = "name") String name,
                                               @Param(value = "time") String time,
                                               @Param(value = "endTime") String endTime,
                                               @Param(value = "type") Integer type,
                                               Page<SecurityBatchEntity> page);
}
